﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RLRT.Common;
using RLRT.Models;

namespace RLRT.Web
{
    public partial class ReceivingQuery : LocalPage
    {
        /// <summary>
        /// 页面加载
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                #region 验证权限

                #endregion

                #region 获取参数

                #endregion

                //初始化
                this.Initialize();
            }

            #region 页面标题

            this.Title = PageTitle.Text;

            #endregion

            #region 页面要素


            #endregion
        }

        #region 初始化

        /// <summary>
        /// 初始化
        /// </summary>
        private void Initialize()
        {
            #region 页面内容

            this.RTNoFrom.Text = string.Empty;
            this.RTNoTo.Text = string.Empty;
            this.OrNoFrom.Text = string.Empty;
            this.OrNoTo.Text = string.Empty;
            this.BomNoFrom.Text = string.Empty;
            this.BomNoTo.Text = string.Empty;
            this.VenNoFrom.Text = string.Empty;
            this.VenNoTo.Text = string.Empty;
            this.OdNoFrom.Text = string.Empty;
            this.OdNoTo.Text = string.Empty;
            this.StationFrom.Text = string.Empty;
            this.StationTo.Text = string.Empty;
            this.DateFrom.Text = DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd");
            this.DateTo.Text = DateTime.Now.ToString("yyyy-MM-dd");

            #endregion

            //绑定列表
            //this.BindList();
        }

        #endregion

        #region 绑定数据

        /// <summary>
        /// 绑定列表
        /// </summary>
        private void BindList()
        {
            using (RTProvider rtProvider = new RTProvider())
            {
                string dateFrom = LocalGlobal.ConvertDateFormat(DateFrom.Text.Trim()).ToString("yyyyMMdd");
                string dateTo = LocalGlobal.ConvertDateFormat(DateTo.Text.Trim()).ToString("yyyyMMdd");
                List.DataSource = rtProvider.GetRTRecordList(RTNoFrom.Text.Trim(), RTNoTo.Text.Trim(), OrNoFrom.Text.Trim(), OrNoTo.Text.Trim(), BomNoFrom.Text.Trim(), BomNoTo.Text.Trim(), VenNoFrom.Text.Trim(), VenNoTo.Text.Trim(), OdNoFrom.Text.Trim(), OdNoTo.Text.Trim(), dateFrom, dateTo, StationFrom.Text.Trim(), StationTo.Text.Trim());
            }
            List.DataBind();
        }

        /// <summary>
        /// 翻页
        /// </summary>
        protected void List_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            List.PageIndex = e.NewPageIndex;
            this.BindList();
        }

        /// <summary>
        /// 行绑定
        /// </summary>
        protected void List_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            switch (e.Row.RowType)
            {
                //数据行
                case DataControlRowType.DataRow:
                    #region 数据绑定

                    e.Row.Cells[4].Text = e.Row.Cells[4].Text.Replace("&amp;nbsp;", "").Trim();

                    #endregion
                    break;

                case DataControlRowType.EmptyDataRow:
                case DataControlRowType.Header:
                case DataControlRowType.Separator:
                case DataControlRowType.Pager:
                case DataControlRowType.Footer:
                default:
                    break;
            }
        }

        #endregion

        #region 操作

        /// <summary>
        /// 确定
        /// </summary>
        protected void OKButton_Click(object sender, EventArgs e)
        {
            this.BindList();
        }

        /// <summary>
        /// 取消
        /// </summary>
        protected void CancelButton_Click(object sender, EventArgs e)
        {
            this.Initialize();
        }

        /// <summary>
        /// 导出
        /// </summary>
        protected void ExportButtion_Click(object sender, EventArgs e)
        {
            this.List.AllowPaging = false;
            this.BindList();
            LocalGlobal.ToExcel(this.List, "收货查询");
            this.List.AllowPaging = true;
            this.BindList();
        }
        #endregion

    }
}